import router from '@/router';
import { isNullPm } from '@/utils/baseMethods';
import { reactive } from 'vue';

export default function importConfig() {
  const base = reactive<any>({
    seriesList: [],
    detailsList: [],
  });

  const init = () => {
    seriesGenerate();
  };

  /**
   * @exports seriesGenerate 自动生成级数器,默认10条数据
   */
  const seriesGenerate = () => {
    base.seriesList = [];
    for (let bm = 1; bm <= 10; bm++) {
      base.seriesList.push(bm + 1);
    }
  };

  /**
   * @exports seriesChange 级数生成器
   * @param param
   */
  const seriesChange = (param) => {
    base.detailsList = [];
    for (let a = 1; a <= param; a++) {
      base.detailsList.push({
        value: null,
        name: null,
        level: a,
      });
    }
  };

  /**
   * @exports templateGeneration 生成模板规则
   * @returns
   */
  const templateGeneration = (): any => {
    let steam = false;
    base.detailsList.forEach((res) => {
      if (isNullPm(res.value)) {
        steam = true;
      }
    });
    if (steam) return false;
    router.push('auditTemplate');
  };

  /**
   * @exports detailsName 绑定名称
   * @param value
   * @param index
   */
  const detailsName = (value, index) => {
    base.detailsList[index].name = value;
  };

  return {
    base,
    init,
    seriesChange,
    templateGeneration,
    detailsName,
  };
}
